#!/bin/bash
#
# (c) 2012 Joe Wollard Denison University
# Cleans and then packages the /System/Library/User Template/English.lproj
# directory for later distribution.
#
# This script requires a single argument, the 'image' name. For example, if 
# you provide "modlang" and the current date is January 3, 2013, the output
# pkg file will be named "user_template_for_modlang-2013-01-03.pkg".
#

id="${1}"
if [ -z "${id}" ];
then
	echo "Please pass an identifier to this script."
	echo "Exmaple: awesome-lab"
	exit
fi

tpl="/System/Library/User Template/English.lproj"

rm -rf "${tpl}/.Trash"
rm -rf "${tpl}/.Trashes"
rm -rf "${tpl}/Library/Caches/"*
rm -rf "${tpl}/Library/Keychains"
rm -rf "${tpl}/Library/Caches/"*
mv "${tpl}/Library/Safari/Bookmarks.plist" "${tpl}/Library/Safari-Bookmarks.plist"
rm -rf "${tpl}/Library/Safari/"*
mv "${tpl}/Library/Safari-Bookmarks.plist" "${tpl}/Library/Safari/Bookmarks.plist"

version=`date "+%Y.%m.%d"`

pkgbuild \
	--root "${tpl}"\
	--identifier "edu.denison.${id}.default-template"\
	--version "${version}"\
	--install-location "/System/Library/User Template/English.lproj"\
	"user_template_for_${id}-${version}.pkg"
